package com.zt.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.zt.pojo.StudentModel;
import com.zt.service.StudentService;

import java.util.ArrayList;
import java.util.List;

public class StudentListener implements ReadListener<StudentModel> {
    private List<StudentModel> dataList = new ArrayList<>();
    private Integer clazzId;
    private StudentService studentService;
    public StudentListener(Integer clazzId, StudentService studentService) {
        this.clazzId = clazzId;
        this.studentService = studentService;
    }

    @Override
    public void invoke(StudentModel studentModel, AnalysisContext analysisContext) {
        dataList.add(studentModel);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        studentService.importStudent(clazzId, dataList);
    }
}
